import {
  getDataList, addEpidmicCamera, getInfo, deleteEpidmicCamera, updateCamera
} from '@/api/innerProject/epidmicControl'

const state = {
  tableData: []
}

const mutations = {
  tableData_list (state, list) {
    state.tableData = list
  }
}

const actions = {
  getEpidmicList (context, payload) {
    return new Promise((resolve, reject) => {
      getDataList(payload).then(res => {
        if (res.data.code === (200 || '200')) {
          context.commit('tableData_list', res.data.data)
        }
        resolve(res.data.data)
      })
        .catch(err => {
          reject(err)
        })
    })
  },
  addCamera (context, payload) {
    payload.projectId = Number(localStorage.getItem('projectId'))
    return new Promise((resolve, reject) => {
      addEpidmicCamera(payload).then(res => {
        // console.log(res)
        if (res.data.code === (200 || '200')) {
          resolve(res.data)
        }
      })
        .catch(err => {
          reject(err)
        })
    })
  },
  deleteCamera (context, payload) {
    return new Promise((resolve, reject) => {
      deleteEpidmicCamera(payload).then(res => {
        if (res.data.code === (200 || '200')) {
        }
        resolve(res.data)
      })
        .catch(err => {
          reject(err)
        })
    })
  },
  updateCamera (context, payload) {
    payload.projectId = Number(localStorage.getItem('projectId'))
    return new Promise((resolve, reject) => {
      updateCamera(payload).then(res => {
        if (res.data.code === (200 || '200')) {
        }
        resolve(res.data)
      })
        .catch(err => {
          reject(err)
        })
    })
  },
  getItemInfo (context, payload) {
    return new Promise((resolve, reject) => {
      getInfo(payload).then(res => {
        if (res.data.code === (200 || '200')) {
        }
        resolve(res.data)
      })
        .catch(err => {
          reject(err)
        })
    })
  }
}
export default {
  namespaced: true,
  actions,
  state,
  mutations
}
